/*	Renegade Scripts.dll
	Scripts by zunnie - mp-gaming.com
	Copyright 2010 zunnie

	This file is part of the Renegade scripts.dll
	The Renegade scripts.dll is free software; you can redistribute it and/or modify it 
	under the terms of the GNU General Public License as published by the Free
	Software Foundation; either version 2, or (at your option) any later
	version. See the file COPYING for more details.
	In addition, an exemption is given to allow Run Time Dynamic Linking of this code 
	with any closed source module that does not contain code covered by this licence.
	Only the source code to the module(s) containing the licenced code has to be released.
*/
#include "scripts.h"
#include "engine.h"
#include "z_m03.h"

void z_m03_missionstart::Created(GameObject *obj)
{
	Commands->Start_Timer(obj,this,6.0f,100);//initialize briefing :)
	Commands->Start_Timer(obj,this,10.0f,101);
	Commands->Start_Timer(obj,this,14.0f,102);
	Commands->Start_Timer(obj,this,18.0f,103);
}
void z_m03_missionstart::Timer_Expired(GameObject *obj, int number)
{
	if (number == 100)
	{
		Commands->Create_2D_WAV_Sound("incmsg.wav");
		Send_Message(255,204,0,"Welcome back Commanders.");
	}
	else if (number == 101)
	{
		Commands->Create_2D_WAV_Sound("incmsg.wav");
		Send_Message(255,204,0,"Clear the Beach Head from any defenses and we will drop in some supplies.");
	}
	else if (number == 102)
	{
		Commands->Create_2D_WAV_Sound("incmsg.wav");
		Send_Message(255,204,0,"This is an Intel Mission. It is vital that some buildings stay online for Intel Operations to finish.");
	}
	else if (number == 103)
	{
		Commands->Create_2D_WAV_Sound("incmsg.wav");
		Send_Message(255,204,0,"Good luck. You're gonna need it.");
	}
}

void z_m03_Poke_Apply_Damage_Object::Poked(GameObject *obj, GameObject *poker)
{
	int team = Get_Int_Parameter("PokerTeam");
	int obj2damage = Get_Int_Parameter("ObjectID");
	float amount = Get_Float_Parameter("DamageAmount");
	const char *warhead = Get_Parameter("Warhead");
	if (Commands->Get_Player_Type(poker) == team)
	{
		Commands->Apply_Damage(Commands->Find_Object(obj2damage),amount,warhead,poker);
		Commands->Send_Custom_Event(obj,Commands->Find_Object(100927),1000,1,0);
		Commands->Send_Custom_Event(obj,Commands->Find_Object(100961),1000,1,0);		
		Destroy_Script();
	}
}

void z_m03_announceprimary::Created(GameObject *obj)
{
	play = true;
}
void z_m03_announceprimary::Entered(GameObject *obj, GameObject *enter)
{
	if (Commands->Is_A_Star(enter))
	{
		if (play)
		{
			play = false;
			Commands->Start_Timer(obj,this,1.0f,100);
			Commands->Start_Timer(obj,this,2.5f,101);
			Commands->Start_Timer(obj,this,5.0f,102);
		}
	}
}
void z_m03_announceprimary::Timer_Expired(GameObject *obj, int number)
{
	if (number == 100)
	{
		Commands->Create_2D_WAV_Sound("nicelanding.wav");
		Send_Message(255,204,0,"Havoc. Nice landing.");
	}
	else if (number == 101)
	{
		Send_Message(255,204,0,"Lead info on the scientists whereabouts.");
	}
	else if (number == 102)
	{
		Send_Message(255,204,0,"Find the Nod Communication Center and download the information.");
		Destroy_Script();
	}
}
void z_m03_announceprimary::Register_Auto_Save_Variables()
{
	Auto_Save_Variable(1,5,&play);
}

void z_m03_controller::Created(GameObject *obj)
{
	transmissiondone = false;
	intelsaved = false;
}
void z_m03_controller::Custom(GameObject *obj, int message, int param, GameObject *sender)
{
	if (message == Get_Int_Parameter("TransmissionDoneMessage"))
	{
		if (param == 1)
		{
			Commands->Start_Timer(obj,this,1801.0f,401);//did they save the intel or not? :hurr:
			Commands->Start_Timer(obj,this,1741.0f,402);//start 1min
			Commands->Start_Timer(obj,this,1501.0f,403);//start 5min
			Commands->Start_Timer(obj,this,1201.0f,404);//start 10min
			Commands->Start_Timer(obj,this,601.0f,405);//start 20min
			Commands->Start_Timer(obj,this,1.0f,406);//start 30min
			transmissiondone = true;
		}
	}
	else if (message == Get_Int_Parameter("IntelSavedMsg"))
	{
		if (param == 1)
		{
			intelsaved = true;
			Commands->Start_Timer(obj,this,5.0f,500);//congrats
		}
	}
	else if (message == Get_Int_Parameter("IntelGuyDiedMsg"))
	{
		//Commands->Start_Timer(obj,this,5.0f,300);//init fail
	}
	else if (message == Get_Int_Parameter("CCDeadMsg"))
	{
		if (param == 1)
		{
			if (transmissiondone)
			{
				//allow
			}
			else if (!transmissiondone)
			{
				Commands->Start_Timer(obj,this,5.0f,100);//init cc fail
			}
		}
	}
	else if (message == Get_Int_Parameter("PPDeadMsg"))
	{
		if (param == 1)
		{
			if (transmissiondone)
			{
				//allow
			}
			else if (!transmissiondone)
			{
				Commands->Start_Timer(obj,this,5.0f,200);//init pp fail
			}
		}
	}
}
void z_m03_controller::Timer_Expired(GameObject *obj, int number)
{
	if (number == 100)//cc premature death
	{
		Commands->Create_2D_WAV_Sound("missionfailed.wav");
		Console_Input("amsg Mission Failed! The Communications Center computer mainframe was destroyed before Intel Data Transmissions were made.");
		Console_Input("win 0");
	}
	else if (number == 200)//pp premature death
	{
		Commands->Create_2D_WAV_Sound("missionfailed.wav");
		Console_Input("amsg Mission Failed! Without Power to the Communications Center Intel Data Transmissions are impossible.");
		Console_Input("win 0");
	}

	else if (number == 300)//intelguy died//moved this code to z_ihasintel
	{
		Commands->Create_2D_WAV_Sound("missionfailed.wav");
		char fail[250];
		sprintf(fail,"amsg %s died. The Intel was lost.",Get_Player_Name(obj));
		Console_Input(fail);
		Console_Input("win 0");
	}

	else if (number == 401)
	{
		if (!intelsaved)
		{
			Commands->Create_2D_WAV_Sound("missionfailed.wav");
			Console_Input("amsg Mission Failed! The Hacked Intel Documents were not brought to the docks for extraction within the the timelimit.");
			Console_Input("win 0");
		}
	}
	else if (number == 402)
	{
		if (!intelsaved)
		{
			Commands->Create_2D_WAV_Sound("1.wav");
			Send_Message(255,204,0,"1 minute remains...");
		}
	}
	else if (number == 403)
	{
		if (!intelsaved)
		{
			Commands->Create_2D_WAV_Sound("5.wav");
			Send_Message(255,204,0,"5 minutes remaining...");
		}
	}
	else if (number == 404)
	{
		if (!intelsaved)
		{
			Commands->Create_2D_WAV_Sound("10.wav");
			Send_Message(255,204,0,"10 minutes remaining...");
		}
	}
	else if (number == 405)
	{
		if (!intelsaved)
		{
			Commands->Create_2D_WAV_Sound("20.wav");
			Send_Message(255,204,0,"20 minutes remaining...");
		}
	}
	else if (number == 406)
	{
		if (!intelsaved)
		{		
			Commands->Create_2D_WAV_Sound("30.wav");
			Send_Message(255,204,0,"30 minutes remaining...");
		}
	}

	else if (number == 500)//wow did they really do it? :V
	{
		Console_Input("amsg Mission Accomplished! The Hacked Intel Documents were brought to safety.");
		Console_Input("win 1");
	}
}
void z_m03_controller::Register_Auto_Save_Variables()
{
	Auto_Save_Variable(1,5,&transmissiondone);
	Auto_Save_Variable(1,5,&intelsaved);
}

void z_m03_ihasintel::Destroyed(GameObject *obj)
{
	int id = Get_Int_Parameter("ControllerID");
	int msg = Get_Int_Parameter("Message");
	int prm = Get_Int_Parameter("Param");
	float delay = Get_Float_Parameter("Delay");
	Commands->Send_Custom_Event(obj,Commands->Find_Object(id),msg,prm,delay);//here


	Commands->Create_2D_WAV_Sound("missionfailed.wav");
	char fail[250];
	sprintf(fail,"amsg %s died. The Intel was lost.",Get_Player_Name(obj));
	Console_Input(fail);
	Console_Input("win 0");
}

void z_m03_computerhax::Created(GameObject *obj)
{
	Commands->Enable_HUD_Pokable_Indicator(obj, true);
	haxed = false;
	allowpoke = true;
	pokerguy = 0;
}
void z_m03_computerhax::Poked(GameObject *obj, GameObject *poker)
{
	if (allowpoke)
	{
		allowpoke = false;
		Commands->Enable_HUD_Pokable_Indicator(obj, false);
		pokerguy = poker;

		Commands->Start_Timer(obj,this,1.0f,100);
		Commands->Start_Timer(obj,this,4.0f,101);
		Commands->Start_Timer(obj,this,7.0f,102);
		Commands->Start_Timer(obj,this,10.0f,103);
		Commands->Start_Timer(obj,this,13.5f,104);
	}
}
void z_m03_computerhax::Timer_Expired(GameObject *obj, int number)
{
	if (number == 100)
	{
		if (Commands->Get_Health(pokerguy) > 1.0f)
		{
			Send_Message(255,204,0,"Accessing...");
			Commands->Create_2D_WAV_Sound("accessing.wav");
		}
		else
		{
			allowpoke = true;
			Commands->Enable_HUD_Pokable_Indicator(obj, true);
		}
	}
	else if (number == 101)
	{
		if (Commands->Get_Health(pokerguy) > 1.0f)
		{
			Send_Message(255,204,0,"Please stand by...");
			Commands->Create_2D_WAV_Sound("plsstandby.wav");
		}
		else
		{
			allowpoke = true;
			Commands->Enable_HUD_Pokable_Indicator(obj, true);
		}
	}
	else if (number == 102)
	{
		if (Commands->Get_Health(pokerguy) > 1.0f)
		{
			Send_Message(255,204,0,"Uplink estabalished...");
			Commands->Create_2D_WAV_Sound("uplinkest.wav");
		}
		else
		{
			allowpoke = true;
			Commands->Enable_HUD_Pokable_Indicator(obj, true);
		}
	}
	else if (number == 103)
	{
		if (Commands->Get_Health(pokerguy) > 1.0f)
		{
			Commands->Create_2D_WAV_Sound("updatecomplete.wav");
			Send_Message(255,204,0,"Update complete...");

			char nice[250];
			sprintf(nice,"%s downloaded the computer mainframe intel documentation to his PDA. Escort %s to the docks for extraction.",Get_Player_Name(pokerguy),Get_Player_Name(pokerguy));
			Send_Message(255,204,0,nice);

			int id = Get_Int_Parameter("ControllerID");
			int msg = Get_Int_Parameter("Message");
			int prm = Get_Int_Parameter("Param");
			float delay = Get_Float_Parameter("Delay");

			Commands->Send_Custom_Event(obj,Commands->Find_Object(100945),3000,1,0);//tell control transmission completed sucesfuly

			char parms[250];
			sprintf(parms,"%d,%d,%d,%f",id,msg,prm,delay);
			Attach_Script_Once(pokerguy,"z_m03_ihasintel",parms);
		}
		else
		{
			allowpoke = true;
			Commands->Enable_HUD_Pokable_Indicator(obj, true);
		}
	}
	else if (number == 104)
	{
		if (Commands->Get_Health(pokerguy) > 1.0f)
		{
			Commands->Create_2D_WAV_Sound("proceeddockarea.wav");
			Send_Message(255,204,0,"Proceed to dock-area. Secure evacuation transportation.");
		}
	}
}
void z_m03_computerhax::Register_Auto_Save_Variables()
{
	Auto_Save_Variable(1,5,&haxed);
	Auto_Save_Variable(1,5,&allowpoke);
	Auto_Save_Variable(1,5,&pokerguy);
}

void z_m03_intelsavezone::Created(GameObject *obj)
{
	issecure = false;
	count = 0;
}
void z_m03_intelsavezone::Custom(GameObject *obj, int message, int param, GameObject *sender)
{
	if (message == 1000)
	{
		if (param == 1)
		{
			count++;
			if (count == 30)
			{
				issecure = true;
				Commands->Create_2D_WAV_Sound("incmsg.wav");
				Send_Message(255,204,0,"Evacuation Transportation Secured.");
			}
		}
	}
}
void z_m03_intelsavezone::Entered(GameObject *obj, GameObject *enter)
{
	if (Commands->Is_A_Star(enter))
	{
		if (issecure)
		{
			if (Is_Script_Attached(enter,"z_m03_ihasintel"))
			{
				int id = Get_Int_Parameter("ControllerID");
				int msg = Get_Int_Parameter("IntelSavedMsg");
				int prm = Get_Int_Parameter("Param");
				Remove_Script(enter,"z_m03_ihasintel");
				Commands->Send_Custom_Event(enter,Commands->Find_Object(id),msg,prm,0);
			}
		}
		else if (!issecure)
		{
			if (Is_Script_Attached(enter,"z_m03_ihasintel"))
			{
				Commands->Create_2D_WAV_Sound("incmsg.wav");
				Send_Message(255,204,0,"Secure the docking area from Nod Troops.");
			}
		}
	}
}
void z_m03_intelsavezone::Register_Auto_Save_Variables()
{
	Auto_Save_Variable(1,5,&issecure);
	Auto_Save_Variable(1,5,&count);
}

void z_m03_basedetectedzone::Created(GameObject *obj)
{
	play = true;
}
void z_m03_basedetectedzone::Entered(GameObject *obj, GameObject *enter)
{
	if (Commands->Is_A_Star(enter))
	{
		if (play)
		{
			play = false;
			Commands->Start_Timer(obj,this,1.0f,100);
			Commands->Start_Timer(obj,this,6.0f,101);
		}
	}
}
void z_m03_basedetectedzone::Timer_Expired(GameObject *obj, int number)
{
	if (number == 100)
	{
		Commands->Create_2D_WAV_Sound("warning_nodbasedetected.wav");
		Send_Message(255,204,0,"Warning. Nod Base detected.");
	}
	else if (number == 101)
	{
		Commands->Create_2D_WAV_Sound("nodbasepowerisonline.wav");
		Send_Message(255,204,0,"Nod Base power is online.");
	}
}
void z_m03_basedetectedzone::Register_Auto_Save_Variables()
{
	Auto_Save_Variable(1,5,&play);
}

void z_m03_enableobjshoredefcannon::Created(GameObject *obj)
{
	play = true;
}
void z_m03_enableobjshoredefcannon::Entered(GameObject *obj, GameObject *enter)
{
	if (Commands->Is_A_Star(enter))
	{
		if (play)
		{
			play =false;
			Commands->Start_Timer(obj,this,1.0f,100);
			Commands->Start_Timer(obj,this,5.0f,101);
		}
	}
}
void z_m03_enableobjshoredefcannon::Timer_Expired(GameObject *obj, int number)
{
	if (number == 100)
	{
		Commands->Create_2D_WAV_Sound("newmissionobjective.wav");
		Send_Message(255,204,0,"New Mission Objective");

	}
	else if (number == 101)
	{
		Commands->Create_2D_WAV_Sound("disableshoredefcannon.wav");
		Send_Message(255,204,0,"Disable Shore Defense Cannon.");
	}

	else if (number == 102)
	{
		Commands->Create_2D_WAV_Sound("objective1new.wav");
		Send_Message(255,204,0,"New Primary Mission Objective.");
		Commands->Start_Timer(obj,this,4.0f,103);
	}
	else if (number == 103)
	{
		Commands->Create_2D_WAV_Sound("incmsg.wav");
		Send_Message(255,204,0,"Locate the Communications Center computer mainframe and download the Intel documents.");
	}
}
void z_m03_enableobjshoredefcannon::Custom(GameObject *obj, int message, int param, GameObject *sender)
{
	if (message == 1234)
	{
		if (param == 1)
		{
			Commands->Create_2D_WAV_Sound("objective1complete.wav");
			Send_Message(255,204,0,"Primary Objective Complete.");
			Commands->Start_Timer(obj,this,4.0f,102);
		}
	}
}
void z_m03_enableobjshoredefcannon::Register_Auto_Save_Variables()
{
	Auto_Save_Variable(1,5,&play);
}

void z_m03_shoredefcannon::Destroyed(GameObject *obj)
{
	Commands->Send_Custom_Event(obj,Commands->Find_Object(1100001),1234,1,0);
}

void z_m03_beachhead::Created(GameObject *obj)
{
	count = 0;
}
void z_m03_beachhead::Custom(GameObject *obj, int message, int param, GameObject *sender)
{
	if (message == 1000)
	{
		if (param == 1)
		{
			count++;
			if (count == 15)
			{
				Commands->Create_2D_WAV_Sound("incmsg.wav");
				Send_Message(255,204,0,"Beach Head Secured.");
			}
		}
	}
}
void z_m03_beachhead::Register_Auto_Save_Variables()
{
	Auto_Save_Variable(1,5,&count);
}



ScriptRegistrant<z_m03_beachhead> z_m03_beachhead_Registrant("z_m03_beachhead","");
ScriptRegistrant<z_m03_enableobjshoredefcannon> z_m03_enableobjshoredefcannon_Registrant("z_m03_enableobjshoredefcannon","");
ScriptRegistrant<z_m03_shoredefcannon> z_m03_shoredefcannon_Registrant("z_m03_shoredefcannon","");
ScriptRegistrant<z_m03_basedetectedzone> z_m03_basedetectedzone_Registrant("z_m03_basedetectedzone","");
ScriptRegistrant<z_m03_computerhax> z_m03_computerhax_Registrant("z_m03_computerhax","ControllerID=1:int,IntelSavedMsg=5000:int,Param=1:int,Message=4000:int,Param=1:int,Delay=0:float");
ScriptRegistrant<z_m03_intelsavezone> z_m03_intelsavezone_Registrant("z_m03_intelsavezone","ControllerID=1:int,IntelSavedMsg=5000:int,Param=1:int");
ScriptRegistrant<z_m03_ihasintel> z_m03_ihasintel_Registrant("z_m03_ihasintel","ControllerID=1:int,Message=4000:int,Param=1:int,Delay=5:float");
ScriptRegistrant<z_m03_controller> z_m03_controller_Registrant("z_m03_controller","CCDeadMsg=1000:int,PPDeadMsg=2000:int,TransmissionDoneMessage=3000:int,IntelGuyDiedMsg=4000:int,IntelSavedMsg=5000:int");
ScriptRegistrant<z_m03_announceprimary> z_m03_announceprimary_Registrant("z_m03_announceprimary","");
ScriptRegistrant<z_m03_Poke_Apply_Damage_Object> z_m03_Poke_Apply_Damage_Object_Registrant("z_m03_Poke_Apply_Damage_Object","PokerTeam=1:int,ObjectID=1:int,DamageAmount=10000:float,Warhead=Death:string");
ScriptRegistrant<z_m03_missionstart> z_m03_missionstart_Registrant("z_m03_missionstart","");
